#include "frmroundplot.h"
#include "ui_frmroundplot.h"
#include "qtimer.h"
#include <QIcon>

frmRoundPlot::frmRoundPlot(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::frmRoundPlot)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏
    btn[0] = ui->btn0;
    btn[1] = ui->btn1;
    btn[2] = ui->btn2;
    btn[3] = ui->btn3;
    btn[4] = ui->btn4;
    btn[5] = ui->btn5;
    /*for(int i = 0;i<6;i++)
    {
        connect(btn[i],SIGNAL(clicked()),this,SLOT(btnclick()));
    }*/

    timerplay = new QTimer(this);
    connect(timerplay,SIGNAL(timeout()),this,SLOT(on_timerplay()));


    this->initForm();
    on_pushButton_clicked();
    ui->ImageBtn->hide();
}

frmRoundPlot::~frmRoundPlot()
{
    delete ui;
}

void frmRoundPlot::initForm()
{
    ui->widget2->setUsedColor(QColor(41, 0, 255),QColor(255, 137, 137));
    ui->widget2->setFreeColor(QColor(50, 50, 50));
    ui->widget2->setRangeTextColor(QColor(103, 103, 103));
    ui->widget2->setValueTextColor(QColor(250, 250, 250));
    ui->widget2->setValueBgColor(QColor(45, 169, 222));
    ui->widget2->setOutBgColor(QColor(202, 225, 255));
    ui->widget2->setCenterBgColor(QColor(67, 205, 128), QColor(60, 179, 113));

    /*ui->widget2->setUsedColor(QColor(165, 220, 62),QColor(255, 50, 137));
    ui->widget2->setFreeColor(QColor(215, 215, 215));
    ui->widget2->setRangeTextColor(QColor(137, 137, 137));
    ui->widget2->setValueTextColor(QColor(52, 155, 218));
    ui->widget2->setValueBgColor(QColor(239, 239, 239));
    ui->widget2->setOutBgColor(QColor(120, 120, 120));
    ui->widget2->setCenterBgColor(QColor(45, 204, 112), QColor(51, 152, 219));*/

    /*ui->widget2->setUsedColor(QColor(255, 0, 0));
    ui->widget2->setFreeColor(QColor(120, 120, 120));
    ui->widget2->setRangeTextColor(QColor(0, 0, 255));
    ui->widget2->setValueTextColor(QColor(0, 0, 0));
    ui->widget2->setValueBgColor(QColor(255, 255, 255));
    ui->widget2->setOutBgColor(QColor(50, 50, 50));
    ui->widget2->setCenterBgColor(QColor(10, 10, 10), QColor(60, 179, 113));*/
}

void frmRoundPlot::on_pushButton_clicked()
{	
    //QString unit = ui->txtUnit->text();
    //double minValue = ui->txtMinValue->text().toDouble();
    //double maxValue = ui->txtMaxValue->text().toDouble();
    //double value = ui->txtValue->text().toDouble();
    QString unit = "℃";
    double minValue = 0;
    double maxValue = 100;
    double value = 100;

    /*ui->widget1->setUnit(unit);
    ui->widget1->setRange(minValue, maxValue);
    ui->widget1->setValue(value);*/

    ui->widget2->setUnit(unit);
    ui->widget2->setRange(minValue, maxValue);
    ui->widget2->setValue(value);
}

void frmRoundPlot::btnclick()
{
    QPushButton *optBtn = qobject_cast<QPushButton *>(sender());

    QString name = sender()->objectName();
    for(int i=0;i<6;i++)
    {
        if(btn[i] == optBtn)
        {
            if (btnisclicked[i] == 0)
            {
                optBtn->setStyleSheet("QPushButton{border-image: url(:/images/"+QString::number(i)+"_2.png);}");
                btnisclicked[i] = 1;
            }
            else
            {
                optBtn->setStyleSheet("QPushButton{border-image: url(:/images/"+QString::number(i)+"_1.png);}");
                btnisclicked[i] = 0;
            }
        }
    }
  //  qDebug()<<"name = "<<name;
}

void frmRoundPlot::on_btn0_clicked()
{
    on_pushButton_clicked();
    if (btnisclicked[0] == 0)
    {
        ui->btn0->setStyleSheet("QPushButton{border-image: url(:/images/0_2.png);}");
        btnisclicked[0] = 1;
        ui->widget2->setUsedColor(QColor(165, 220, 62),QColor(255, 50, 137));
    }
    else
    {
        ui->btn0->setStyleSheet("QPushButton{border-image: url(:/images/0_1.png);}");
        btnisclicked[0] = 0;
        ui->widget2->setUsedColor(QColor(41, 0, 255),QColor(255, 137, 137));
    }
}

void frmRoundPlot::on_btn1_clicked()
{
    on_pushButton_clicked();
    if (btnisclicked[1] == 0)
    {
        ui->btn1->setStyleSheet("QPushButton{border-image: url(:/images/1_2.png);}");
        btnisclicked[1] = 1;
        ui->widget2->setValueTextColor(QColor(100, 100, 100));
    }
    else
    {
        ui->btn1->setStyleSheet("QPushButton{border-image: url(:/images/1_1.png);}");
        btnisclicked[1] = 0;
        ui->widget2->setValueTextColor(QColor(250, 250, 250));
    }
}

void frmRoundPlot::on_btn2_clicked()
{
    on_pushButton_clicked();
    if (btnisclicked[2] == 0)
    {
        ui->btn2->setStyleSheet("QPushButton{border-image: url(:/images/2_2.png);}");
        btnisclicked[2] = 1;
        ui->widget2->setValueBgColor(QColor(150, 150, 45));
    }
    else
    {
        ui->btn2->setStyleSheet("QPushButton{border-image: url(:/images/2_1.png);}");
        btnisclicked[2] = 0;
        ui->widget2->setValueBgColor(QColor(45, 169, 222));
    }
}

void frmRoundPlot::on_btn3_clicked()
{
    on_pushButton_clicked();
    if (btnisclicked[3] == 0)
    {
        ui->btn3->setStyleSheet("QPushButton{border-image: url(:/images/3_2.png);}");
        btnisclicked[3] = 1;
        ui->widget2->setOutBgColor(QColor(220, 190, 180));
    }
    else
    {
        ui->btn3->setStyleSheet("QPushButton{border-image: url(:/images/3_1.png);}");
        btnisclicked[3] = 0;
        ui->widget2->setOutBgColor(QColor(202, 225, 255));
    }
}

void frmRoundPlot::on_btn4_clicked()
{
    on_pushButton_clicked();
    if (btnisclicked[4] == 0)
    {
        ui->btn4->setStyleSheet("QPushButton{border-image: url(:/images/4_2.png);}");
        btnisclicked[4] = 1;
        ui->widget2->setCenterBgColor(QColor(45, 45, 45), QColor(90, 90, 90));
    }
    else
    {
        ui->btn4->setStyleSheet("QPushButton{border-image: url(:/images/4_1.png);}");
        btnisclicked[4] = 0;
        ui->widget2->setCenterBgColor(QColor(67, 205, 128), QColor(60, 179, 113));
    }
}

void frmRoundPlot::on_timerplay()
{

   ///////////////////////////////////////////////////////////////////
       ui->ImageBtn->show();
       if (index>=3)
           index = 0;
       else
           index++;

       QIcon ico(images[index]);

       ui->ImageBtn->setIcon(ico);
       ui->ImageBtn->setIconSize(QSize(800,800));
       ui->ImageBtn->setFlat(false);
   /////////////////////////////////////////////////////////////////////

}

void frmRoundPlot::on_ImageBtn_clicked()
{
    //timerplay->start(2000);
    ui->ImageBtn->hide();
    timerplay->stop();
}

void frmRoundPlot::on_btn5_clicked()
{
    ui->ImageBtn->show();
   timerplay->start(2000);
}
